Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

365
Views
Gatsby and WPGraphQL - Build Error "Cannot query field "pages" on type "Query""

I'm completely new to WPGraphQL and I'm having some bother with building a Gatsby site from my new Wordpress endpoint. When I execute the following query to my endpoint in Postman, I get the page data back successfully:

 query MyQuery {
     pages {
        edges {
            node {
                id
                slug
                status
            }
        }
     }
  }

However when I attempt to build the Gatsby site, I get the following:

ERROR #85923 GRAPHQL

There was an error in your GraphQL query:

Cannot query field "pages" on type "Query".

The relevant code in gatsby-node.js is:

const _ = require('lodash')
const path = require('path')
const { createFilePath } = require('gatsby-source-filesystem')
const { paginate } = require('gatsby-awesome-pagination')

const getOnlyPublished = edges =>
  _.filter(edges, ({ node }) => node.status === 'publish')

exports.createPages = ({ actions, graphql }) => {
  const { createPage } = actions

  return graphql(`
    {
      pages {
        edges {
          node {
            id
            slug
            status
          }
        }
      }
    }
  `)
    .then(result => {
      if (result.errors) {
        result.errors.forEach(e => console.error(e.toString()))
        return Promise.reject(result.errors)
      }

Gatsby config:

module.exports = {
  siteMetadata: {
    siteUrl: "https://www.yourdomain.tld",
    title: "graphql-test",
  },
  plugins: [
    {
      resolve: "gatsby-source-wordpress",
      options: {
        url: "https://*********/graphql",
      },
    },
    "gatsby-plugin-sass",
    "gatsby-plugin-react-helmet",
    "gatsby-plugin-sitemap",
  ],
};

This is a brand new test Gatsby site created with gatsby new, all plugins are the latest version.

Any help with this greatly appreciated!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It turns out that Gatsby uses a slightly different format for its graphql queries. What I should have had in gatsby-node.js was this:

  return graphql(`
    {
      allWpPage {
          nodes {
            id
            slug
            status
        }
      }
    }
  `)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!